/**
 * 导出 DTwin 项目场景至 GLTF 文件.
 */
let GLTFExporter = HaloEngine.ThreeExt.GLTFExporter;

// 初始化上下文
let scene = Sandbox.defaults().SCENE_MANAGER.active;

// [参数设置] 导出目标: SELECTED | ALL
let target = 'ALL';
let root = target === 'SELECTED' ? scene.activeObject : scene;

// 异常检测
if (root != null) {

  // 导出 GLTF 文件
  let exporter = new GLTFExporter();
  exporter.parse(root.group, gltf => {
      const link = document.createElement('a');
      link.href = URL.createObjectURL(new Blob([JSON.stringify(gltf)], { type: 'text/plain' }));
      link.download = 'scene.gltf';
      link.click();
  });
} else {
  console.warn('No GameObject selected, or activate scene.');
}